AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )

include('shared.lua')

ENT.Dropped = false;
ENT.typ = "ammo"
//models/props_junk/wood_crate001a_damaged.mdl
function ENT:Initialize()

if(self.typ == "ammo") then
self.Entity:SetModel("models/props_junk/wood_crate001a_damaged.mdl")
self.Entity:SetModelScale(self.Entity:GetModelScale()*0.2 ,0.2)
elseif(self.typ == "weapon") then
self.Entity:SetModel("models/weapons/w_smg1.mdl")
self.Entity:SetModelScale(self.Entity:GetModelScale() ,1)
end
	
	self.Entity:SetPos(self:GetPos()+Vector(0,0,25))
	self.Entity:SetAngles(Angle(0,0,0))
	self.Entity:PhysicsInit( SOLID_VPHYSICS )
	self.Entity:SetMoveType( MOVETYPE_NONE )
	self.Entity:SetSolid( SOLID_VPHYSICS )
	self.Entity:SetCollisionGroup( COLLISION_GROUP_DEBRIS_TRIGGER )
	self.Entity:SetCollisionBounds( Vector( -16, -16, -16 ), Vector( 16, 16, 0 ) )

	local phy = self.Entity:GetPhysicsObject()
	if phy:IsValid() then phy:Wake() end

	self.Entity:SetTrigger(true)


		self.ID = math.random(0,1000)
		
end

function ENT:SetPickup( pickup )

end

function ENT:Settyp( typ )

self.typ = typ

end

-- function ENT:SpawnFunction( ply, tr )

	-- if ( !tr.Hit ) then return end
	
	-- local SpawnPos = tr.HitPos + tr.HitNormal * 16
	-- local ent = ents.Create( "sent_pickup" )
		-- ent:Settyp("ammo")
		-- ent:SetPos( SpawnPos )
		-- ent:Spawn()
		-- ent:Activate()
	
	-- return ent
	
-- end




function ENT:Touch( entity )
	if ( self:GetActiveTime() > CurTime() ) then return end
	if (!entity:IsPlayer()) then return end

	--entity:Give( self.Entity:GetNWString("classname") )
	self:DoAmmoGive( entity )
	self.Entity:EmitSound("misc/w_pkup.wav")
timer.Create( ""..(self.ID).."", 5, 1, function()

	self:SetNoDraw(false)
	self:SetSolid( SOLID_VPHYSICS )
	end )
	Msg("touched\n")
	if( self.Dropped == true ) then
		self:SetNoDraw(true)
		self:SetSolid( SOLID_NONE )
		return
	end
	
	local re = self.RespawnTime or 5
	self:SetActiveTime( CurTime() + re )
	

	
	

end
